DXL Binary Operators Definitions :: with More Than Two Parameters?

Many programming languages support extending symbolic operators to support new types. From my experiences, unary operator definitions take one (1) parameter; binary operator definitions take two (2) parameters; and so on.

While the above is implementable for DXL, there are also other variations one can define, but I can't figure out how they would be invoked.

In the DXL help file, one can find:

::do(SignatureEntry&, SignatureInfo, void) 
// Declaration 
void ::do(SignatureEntry& sigentry, SignatureInfo si, void) 
::do(AccessRec&, SignatureInfo, void) 
// Declaration 
void ::do(AccessRec& ar, SignatureInfo si, void) 
::do(AccessRec&, SignatureInfoSpecifier__, void) 
// Declaration 
void ::do(AccessRec& ar, SignatureInfoSpecifier__ sis, void)

 


You can define your own. They compile fine but I have no idea how to call it.

For example this compiles like a champ:

 

 

 

string ::.(string p1, int p2, bool p3, string p4) {
    return "" (upper(p1)) "" (p2+5) "" (p3) "" (lower(p4)) "";
}



QUESTION:
Does anyone know how to invoke such a function?

Is it useful? I can't say without knowing what the invocation looks like.



 

 


SystemAdmin - Tue Jun 22 09:34:48 EDT 2010

Re: DXL Binary Operators Definitions :: with More Than Two Parameters?
a_vestlin - Tue Jun 22 11:08:35 EDT 2010

The . is a binary operator and therefore a declaration should look like this:

string ::.(string s, int i)
{
    int j
        string sReturn = ""
        if ( i > 0 )
        {
                for j in 0:i do
                {
                        sReturn = sReturn s
                }
        }
 
        return(sReturn)
                
}
string s = "hello"
string result = s.4
print result

 


The do operator is used for "for"-loops and as far as I know it is not possible to implement these in DXL.
I think they are coded in the underlying C-code.
/Anders

 

Re: DXL Binary Operators Definitions :: with More Than Two Parameters?
SystemAdmin - Tue Jun 22 11:32:03 EDT 2010

a_vestlin - Tue Jun 22 11:08:35 EDT 2010

The . is a binary operator and therefore a declaration should look like this:

string ::.(string s, int i)
{
    int j
        string sReturn = ""
        if ( i > 0 )
        {
                for j in 0:i do
                {
                        sReturn = sReturn s
                }
        }
 
        return(sReturn)
                
}
string s = "hello"
string result = s.4
print result

 


The do operator is used for "for"-loops and as far as I know it is not possible to implement these in DXL.
I think they are coded in the underlying C-code.
/Anders

 

I agree with you that "." is "supposed to" be for binary (two argument) use.
However, you call see from my example that DXL did allow me to "implement" it (to my surprise it compiled fine.) Forget about the operator symbol and whether it makes sense. More generally, I was wondering how one would call an extended operator that has more than two parameters.

QUESTION:
Given the compiled implementation, how is is called? The code I gave was a simple, silly example for illustration purposes of concept. Consideration of any real use depends on how neat (or ugly) the invocation (call to it) is.

POSSIBILITIES:
1) Even though the code compiled, there may be no valid syntax to call it.
2) It is callable, but the syntax is illusive and undocumented.

Re: DXL Binary Operators Definitions :: with More Than Two Parameters?
Mathias Mamsch - Wed Jun 23 07:56:46 EDT 2010

SystemAdmin - Tue Jun 22 11:32:03 EDT 2010
I agree with you that "." is "supposed to" be for binary (two argument) use.
However, you call see from my example that DXL did allow me to "implement" it (to my surprise it compiled fine.) Forget about the operator symbol and whether it makes sense. More generally, I was wondering how one would call an extended operator that has more than two parameters.

QUESTION:
Given the compiled implementation, how is is called? The code I gave was a simple, silly example for illustration purposes of concept. Consideration of any real use depends on how neat (or ugly) the invocation (call to it) is.

POSSIBILITIES:
1) Even though the code compiled, there may be no valid syntax to call it.
2) It is callable, but the syntax is illusive and undocumented.

uhm ... if you compile a function like this ::.(int a, int b, int c) you can always call it using ::.(1,2,3). No magic syntax there i guess ...

When you use a.b in DXL code, then the parser will look for a fitting operator ::.(a,b) which fits the types of a and b. If you use a.b.c then the parser will do a.(b.c) and hopefully get the type of (b.c) right.

What you can do however is define different functions for chaining binary operator calls:
 

Skip ::..(int a, Skip b) {
    int count = -1 
    find(b, -1, count)
    put(b, -1, ++count,true) 
    put(b, count, a)
    return b
}
 
Skip ::..(int a, int b) {
   Skip x = create() 
   put (x, -1, 1) 
   put (x, 0, b )
   put (x, 1, a )
   return x
}
 
 
void create (Skip x) {
   int val
   for val in x do {
     if ((key x) int != -1) {
            print "Processing value: " val "\n"
     }
   }
}
 
create 3 4 5 6 7

 


Hope that helps in the discussion ... Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: DXL Binary Operators Definitions :: with More Than Two Parameters?
SystemAdmin - Sun Feb 24 12:08:18 EST 2013

The operator declared by

void ::do(SignatureEntry&, SignatureInfo, void)

is required whwn writing:

SignatureEntry se
for se in (SignatureInfo si) do {
....
}

So the operator declaration using three arguments is just another interesting DXl syntax ...

Re: DXL Binary Operators Definitions :: with More Than Two Parameters?
Mathias Mamsch - Sun Feb 24 14:47:00 EST 2013

SystemAdmin - Sun Feb 24 12:08:18 EST 2013
The operator declared by

void ::do(SignatureEntry&, SignatureInfo, void)

is required whwn writing:

SignatureEntry se
for se in (SignatureInfo si) do {
....
}

So the operator declaration using three arguments is just another interesting DXl syntax ...

In fact other languages also support ternary operators. DXL lend those from C. The for-do, ?: There are some ternary operators, but you cannot redeclare them since they all use code blocks as parameters, which are handled at 'compile-time' with a hard wired syntax, when the parser parses the DXL. You cannot handle them from DXL at runtime. Therefore the question about having operators with more than two parameters is kind of misleading. Only unary and binary operators can be redeclared in DXL. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS